#import cv2
import time,PIL,os
from PIL import ImageGrab
import numpy as np
import time
from tempfile import NamedTemporaryFile
import easyocr
from concurrent.futures import ThreadPoolExecutor
import sys

#截图
class ScreenCut:
    def __init__(self):
        if not os.path.exists("E:/ningyuan/sumimoto/Curelasto/tmp/"):
            os.makedirs("E:/ningyuan/sumimoto/Curelasto/tmp/")
        try:
            os.remove("E:/ningyuan/sumimoto/Curelasto/tmp/scr.png")
            os.remove("E:/ningyuan/sumimoto/Curelasto/tmp/cut.png")
        except:pass
        self.scrImg = open("E:/ningyuan/sumimoto/Curelasto/tmp/scr.png","wb+")
        self.cutImg = open("E:/ningyuan/sumimoto/Curelasto/tmp/cut.png","wb+")
    def cut(self):
        self.scrren_cut()
        #print("截图完成")
    def scrren_cut(self):
        img = ImageGrab.grab(bbox=(
                1000,       # 起始x坐标
                700,       # 起始y坐标
                1000+500,  # 起始x + 宽度
                700+200   # 起始y + 高度
            ))
        img.save(self.cutImg.name)


cut = ScreenCut()
cut.cut()

reader = easyocr.Reader(['en'])
result = reader.readtext("E:/ningyuan/sumimoto/Curelasto/tmp/cut.png")

if not result:
    #print("未识别到文字")
    print("Text not recognized")
    exit()

#extracted_text = []
extracted_text = ''
for detection in result:
    #extracted_text.append(detection[1])
    #print(detection[1])
    extracted_text += detection[1]

print(extracted_text)